package com.gjh.study.mybatis.mapper2;

import com.gjh.study.mybatis.domain.Order;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author guangjh
 * @version 1.0
 * @date 2020/7/12 7:40
 */
public interface OrderMapper {
    @Select("select * from tb_order where id = #{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "code", column = "code"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "user_id",
                    one = @One(select = "com.gjh.study.mybatis.mapper2.UserMapper.selectUserById", fetchType = FetchType.EAGER)),
            @Result(property = "articles", column = "id",
                    many = @Many(select = "com.gjh.study.mybatis.mapper2.ArticleMapper.selectArticleByOrderId", fetchType = FetchType.LAZY))
    })
    Order selectOrderById(int id);

    @Select("select * from tb_order where user_id = #{id}")
    List<Order> selectOrderByUserId(int id);
}
